package idv.arthur.jenkins;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

import com.google.gson.Gson;

public class GetJsonFromJenkins {
	
	
	public static void main(String[] args) throws Exception {

	    String json = readUrl("http://10.144.97.99:8330/jenkins/job/3C/api/json");

	    JenkinsJobFull jobFull = new Gson().fromJson(json, JenkinsJobFull.class);
	    System.out.println(jobFull.getLastBuild().getUrl());
	}

	private static String readUrl(String urlString) throws Exception {
		BufferedReader reader = null;
		try {
			URL url = new URL(urlString);
			reader = new BufferedReader(new InputStreamReader(url.openStream()));
			StringBuffer buffer = new StringBuffer();
			int read;
			char[] chars = new char[1024];
			while ((read = reader.read(chars)) != -1)
				buffer.append(chars, 0, read);

			return buffer.toString();
		} finally {
			if (reader != null)
				reader.close();
		}
	}
}

class JenkinsJobFull {
	private LastBuild lastBuild = new LastBuild();

	public LastBuild getLastBuild() {
		return lastBuild;
	}

	public void setLastBuild(LastBuild lastBuild) {
		this.lastBuild = lastBuild;
	}
}

class LastBuild {
	private int number = 0;
	private String url = "";
	
	public int getNumber() {
		return number;
	}
	public void setNumber(int number) {
		this.number = number;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
}


class JenkinsJob {
	private String result;
	private int number;
	
	
}